package com.qf.common.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import javax.annotation.Resource;



@Configuration
@EnableOpenApi
public class SwaggerConfig {
    @Resource
    private SwaggerConfigProperties configProperties;

    /**
     * @return
     */
    @Bean
    public Docket createDocket(ApiInfo apiInfo) {
        return new Docket(DocumentationType.OAS_30)
                // 生产关闭
                .enable(configProperties.isEnable())
                //
                .apiInfo(apiInfo).select()
                // 扫描生成API的基础包
                .apis(RequestHandlerSelectors.basePackage(configProperties.getBasePackages()))
                // 为所有的路径生成API在线文档
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //   标题
                .title(configProperties.getTitle())
                // 描述
                .description(configProperties.getDescription())
                //  版本号
                .version(configProperties.getVersion())
                // 作者信息
                .contact(new Contact(configProperties.getContactName(), configProperties.getContactUrl(), configProperties.getContactEmail()))
                //
                .build();


    }

}
